﻿//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;

namespace Microsoft.Ted.Wacel
{
    public class DataPoint
    {
        public List<DimensionNode> Coordinates { get; set; }
        public double Value { get { return mData.Value; } set { mData.Value = value; } }
        public double Min { get { return mData.Min; } }
        public double Max { get { return mData.Max; } }
        public double Average { get { return mData.Average; } }
        public long Version { get { return mData.Version; } }

        private NodeData mData = new NodeData();

        private string mKey = null;
        public DataPoint()
        {
            Coordinates = new List<DimensionNode>();
        }
        public List<DataPoint> Drilldown(string dimension)
        {
            return null;
        }
        public DataPoint ReplaceCoordinate(DimensionNode node)
        {
            DataPoint ret = new DataPoint();
            for (int i = 0; i < Coordinates.Count; i++)
            {
                if (Coordinates[i].ParentDimension == node.ParentDimension)
                    ret.Coordinates.Add(node);
                else
                    ret.Coordinates.Add(Coordinates[i]);
            }
            return ret;
        }
        internal void SetNodeData(NodeData data)
        {
            if (data == null)
                throw new ArgumentNullException();
            mData = data;
        }
        public string Key
        {
            get
            {
                if (mKey == null)
                {
                    for (int i = 0; i < Coordinates.Count; i++)
                        mKey += Coordinates[i].ParentDimension.Name + ":" + Coordinates[i].Name + ":";
                }
                return mKey;
            }
        }
        
    }
}
